'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
const path = require('path');
module.exports = (app) => {
	const directory = path.join(app.config.baseDir, 'app/validate');
	app.loader.loadToApp(directory, 'validate');

	const { router, controller, jwt } = app;
	router.get('/', controller.home.index);

	// // 用户相关
	router.post('/api/userLogin', controller.user.login); // 用户登录
	router.post('/api/testLogin', controller.user.testLogin); // 开发测试登录

	// 单词
	router.get('/api/user-word-count', jwt, controller.word.getUserWordCount);// 获取主页用户单词总数
	router.get('/api/word-count', jwt, controller.word.getWordCount);// 获取单词总数
	router.get('/api/learned-word-count', jwt, controller.word.getLearnedWordCount);// 获取单词总数
	router.get('/api/unlearend-words', jwt, controller.word.getUnlearnedWords);// 获取单词总数
	router.post('/api/get-words-list', jwt, controller.word.getWordsList);// 分页查询单词
	router.post('/api/update-word', jwt, controller.word.updateWord);// 修改单词
	router.post('/api/delete-word', jwt, controller.word.deleteWord);// 删除单词

	// 复习
	router.get('/api/getUnReviewWords', jwt, controller.word.getUnReviewWords);// 查询复习单词
	router.post('/api/updateReviewTime', jwt, controller.progress.updateReviewTime);// 查询复习单词

	// 进度
	router.post('/api/setProgress', jwt, controller.progress.setProgress);// 获取单词总数
	router.get('/api/getTodayProgressCount', jwt, controller.progress.getTodayProgressCount);// 获取单词总数
	router.get('/api/getProgressCount', jwt, controller.progress.getProgressCount);// 获取进度数据

	// 记录
	router.post('/users/study-days', jwt, controller.userStudyDay.recordStudyDay);// 记录用户学习天数
	router.get('/api/study-days', jwt, controller.userStudyDay.getStudyDays);// 获取用户的学习天数
	router.get('/api/study-total-days', jwt, controller.userStudyDay.getStudyTotalDays); // 获取用户的学习总天数

	// 单词收藏相关路由
	router.post('/api/favorites', jwt, controller.wordFavorites.create); // 收藏单词
	router.post('/api/favorites/:wordId', jwt, controller.wordFavorites.destroy); // 取消收藏
	router.get('/api/favorites', jwt, controller.wordFavorites.index); // 收藏列表
	router.get('/api/favorites/check/:wordId', jwt, controller.wordFavorites.check); // 检查是否收藏
};
